
function ajxValidator(objs) {

    /**
    - Following Properties are Allowed
    controlID - ID of Control "#ID" format
    message   - Error Message you want to Show
    minlength,manlength  - either use combined or seperately

    - Supports Following Function

    command: write any custom logic for this function and either return true/false

    Example:
        
        Shiptostate: {
            controlID: "#ShipToState",
            message: "Please Select a Ship to State"
        }

        Shiptostate should be passed as a parameter to ajxValidator-   ajxValidator(Shiptostate).validator()
        it will return true or false, if false then handle your request (ie, reject form submit)

    **/

    var vObj = {


        validator: function () { // mini form validate api

            var errors = [];

            for (obj in objs) {

                var parentObj = (objs[obj]);
                var control;
                var errMsg = parentObj.message;

                //run custom command function
                if (typeof parentObj.command === "function") { // run custom exec
                    var result = parentObj.command();
                    if (!result) errors.push(errMsg);
                } else if (typeof parentObj.minlength != "undefined" && typeof parentObj.maxlength != "undefined") {
                    control = $(parentObj.controlID).val().trim();
                    if ((control.length < parentObj.minlength) || (control.length > parentObj.maxlength) ) { // min & max length check
                        errors.push(errMsg);
                    }                
                } else if (typeof parentObj.minlength != "undefined") { // check min length only
                    control = $(parentObj.controlID).val().trim();
                    if (control.length < parentObj.minlength) {
                        errors.push(errMsg);
                    }
                } else if (typeof parentObj.maxlength != "undefined") { // check max length only
                    control = $(parentObj.controlID).val().trim();
                    if (control.length > parentObj.maxlength) {
                        errors.push(errMsg);
                    }
                } else {
                    control = $(parentObj.controlID).val().trim();
                    if (control == '') {
                        errors.push(errMsg);
                    }
                }

            }

            if (errors.length > 0) {
                alert(errors.join("\n"));
                return false;
            } else {
                return true;
            }


        }

    }

    return vObj;

} // function